home *** CD-ROM | disk | FTP | other *** search
Text File | 2009-03-03 | 42.9 KB | 1,290 lines |
- package
- {
- import com.balsamiq.events.FileManagerEvent;
- import com.balsamiq.file.FileDescriptor;
- import com.balsamiq.file.FileManager;
- import com.balsamiq.keygen.BalsamiqKeyGenerator;
- import com.balsamiq.keygen.descriptors.SerialKeyFieldsDescriptor;
- import com.plus9.mockups.Mockups;
- import com.plus9.mockups.dialogs.AreYouSure;
- import com.plus9.mockups.events.MockupModelEvent;
- import com.plus9.mockups.model.ICookieManager;
- import com.plus9.mockups.model.IStorageManager;
- import com.plus9.mockups.ui.LoadingPopUp;
- import flash.data.SQLConnection;
- import flash.data.SQLMode;
- import flash.data.SQLStatement;
- import flash.desktop.Clipboard;
- import flash.desktop.ClipboardFormats;
- import flash.display.BitmapData;
- import flash.display.DisplayObject;
- import flash.events.Event;
- import flash.events.FileListEvent;
- import flash.events.TimerEvent;
- import flash.filesystem.File;
- import flash.filesystem.FileMode;
- import flash.filesystem.FileStream;
- import flash.net.FileFilter;
- import flash.utils.ByteArray;
- import flash.utils.Timer;
- import mx.controls.Alert;
- import mx.core.Application;
- import mx.core.IFlexDisplayObject;
- import mx.managers.CursorManager;
- import mx.managers.PopUpManager;
-
- public class StorageManagerAir extends FileManager implements IStorageManager
- {
- protected var _ultimateAction:String;
-
- protected var _pathsToExport:Array;
-
- protected var _reloadDialog:AreYouSure;
-
- protected var _lastOpenPath:String;
-
- protected var _mockups:Mockups;
-
- protected var _exportingDlg:LoadingPopUp;
-
- protected var _dbFile:File;
-
- protected var _activateDialog:Activate;
-
- protected var _exportPNGDialog:ExportPNGConfirmationDialog;
-
- protected var _multipleUnsavedDlg:SaveMultipleDialog;
-
- protected var _openFile:File;
-
- protected var _saveAsFile:File;
-
- protected var _sqlConnection:SQLConnection;
-
- protected var _activated:Boolean = false;
-
- protected var _exportAllTargetDirPath:String;
-
- protected var _pathsToExportIndex:uint;
-
- protected var _exportedPaths:String;
-
- protected var _exportAllFile:File;
-
- protected var _isExportingAll:Boolean = false;
-
- protected var _confirmDlg:ConfirmationDialog;
-
- protected var _logger:FileLogger;
-
- protected var _checkForUpdatesTimer:Timer;
-
- protected var _unsavedChangesDlg:UnsavedChangesDialog;
-
- protected var _exportingAllAlwaysOverwrite:Boolean = false;
-
- public function StorageManagerAir(param1:Mockups, param2:Boolean = true, param3:String = "")
- {
- var sqlStatement:SQLStatement = null;
- var res:Array = null;
- var p_mockups:Mockups = param1;
- var p_restoreSession:Boolean = param2;
- var p_build:String = param3;
- super();
- _mockups = p_mockups;
- Application.application.stage.nativeWindow.addEventListener(Event.CLOSING,onClosing);
- _dbFile = File.applicationStorageDirectory.resolvePath("MockupsOnAir.db");
- _sqlConnection = new SQLConnection();
- try
- {
- _sqlConnection.open(_dbFile,SQLMode.READ);
- sqlStatement = new SQLStatement();
- sqlStatement.sqlConnection = _sqlConnection;
- sqlStatement.text = "SELECT status FROM activation WHERE id = 0";
- sqlStatement.execute();
- res = sqlStatement.getResult().data;
- _activated = res.length == 1 && res[0].status == true;
- }
- catch(e:Error)
- {
- _activated = false;
- }
- _sqlConnection.close();
- _logger = new FileLogger(p_build);
- _checkForUpdatesTimer = new Timer(5000,0);
- _checkForUpdatesTimer.addEventListener(TimerEvent.TIMER,onCheckForUpdates);
- if(p_restoreSession)
- {
- restoreSession();
- }
- }
-
- protected function openActivateDialog() : void
- {
- if(Boolean(_activateDialog) && Boolean(_activateDialog.parent))
- {
- return;
- }
- _activateDialog = Activate(PopUpManager.createPopUp(DisplayObject(Application.application),Activate,true));
- _activateDialog.addEventListener("myActivate",onActivateDialogActivate);
- _activateDialog.init(_mockups.inputManager);
- _activateDialog.storageManager = this;
- PopUpManager.centerPopUp(IFlexDisplayObject(_activateDialog));
- }
-
- protected function onFileSelectMultiple(param1:FileListEvent) : void
- {
- var _loc3_:File = null;
- var _loc4_:Boolean = false;
- var _loc5_:String = null;
- var _loc6_:uint = 0;
- var _loc7_:FileDescriptor = null;
- _openFile.removeEventListener(FileListEvent.SELECT_MULTIPLE,onFileSelectMultiple);
- _openFile.removeEventListener(Event.CANCEL,onFileCancel);
- var _loc2_:uint = 0;
- while(_loc2_ < param1.files.length)
- {
- _loc3_ = File(param1.files[_loc2_]);
- _loc3_.removeEventListener(FileListEvent.SELECT_MULTIPLE,onFileSelectMultiple);
- _loc3_.removeEventListener(Event.CANCEL,onFileCancel);
- _lastOpenPath = cleanPath(_loc3_.nativePath);
- loadFileFromDisk(_loc3_.nativePath);
- _loc4_ = false;
- _loc6_ = 0;
- for each(_loc7_ in _files)
- {
- if(++_loc6_ > 2)
- {
- _loc4_ = false;
- break;
- }
- if(_loc7_.path.indexOf("?") != -1 && !_loc7_.isDirty && !_loc4_)
- {
- _loc4_ = true;
- _loc5_ = _loc7_.path;
- }
- else if(_loc7_.path == _loc3_.nativePath)
- {
- }
- }
- if(_loc4_)
- {
- closeFile(_loc5_);
- }
- _loc2_++;
- }
- _openFile.removeEventListener(FileListEvent.SELECT_MULTIPLE,onFileSelectMultiple);
- _openFile.removeEventListener(Event.CANCEL,onFileCancel);
- _openFile = null;
- }
-
- override public function loadFileFromDisk(param1:String) : String
- {
- log("loadFileFromDisk:" + param1);
- param1 = cleanPath(param1);
- var _loc2_:String = loadDataIntoMemory(param1);
- if(_loc2_)
- {
- selectFile(param1);
- saveSession();
- }
- else
- {
- createNewFile();
- }
- return _loc2_;
- }
-
- protected function onCheckForUpdates(param1:TimerEvent = null) : void
- {
- var _loc2_:FileDescriptor = FileDescriptor(_files[_currentPath]);
- if(_loc2_ == null || _loc2_.timeStamp == -1)
- {
- _checkForUpdatesTimer.stop();
- return;
- }
- if(_reloadDialog != null && Boolean(_reloadDialog.parent))
- {
- return;
- }
- var _loc3_:File = new File(_currentPath);
- if(_loc3_.modificationDate.getTime() > _loc2_.timeStamp)
- {
- _reloadDialog = AreYouSure(PopUpManager.createPopUp(DisplayObject(Application.application),AreYouSure,true));
- _reloadDialog.title = "File Changed on Disk";
- _reloadDialog.message = "The file you are editing was changed on disc.\nWould you like to reload the file and accept the changes?";
- _reloadDialog.okLabel = "Reload the File";
- _reloadDialog.addEventListener("yes",onReloadYes);
- _reloadDialog.addEventListener("no",onReloadNo);
- _reloadDialog.init(_mockups.inputManager);
- PopUpManager.centerPopUp(IFlexDisplayObject(_reloadDialog));
- _checkForUpdatesTimer.stop();
- }
- }
-
- public function isValidKey(param1:String, param2:String) : Boolean
- {
- var d:SerialKeyFieldsDescriptor = null;
- var p_name:String = param1;
- var p_key:String = param2;
- var e:Boolean = true;
- e &&= p_name.length > 2;
- try
- {
- d = BalsamiqKeyGenerator.decriptKey(p_key);
- e &&= d.productName == "MockupsConfluence" || d.productName == "MockupsJIRA" || d.productName == "MockupsXWiki" || d.productName == "MockupsAir";
- e &&= BalsamiqKeyGenerator.cleanCompanyName(p_name) == BalsamiqKeyGenerator.cleanCompanyName(d.companyName);
- }
- catch(e:Error)
- {
- e = false;
- }
- return e;
- }
-
- protected function promptToSave() : void
- {
- var _loc3_:FileDescriptor = null;
- if(_unsavedChangesDlg && _unsavedChangesDlg.parent || _multipleUnsavedDlg && _multipleUnsavedDlg.parent)
- {
- return;
- }
- var _loc1_:uint = 0;
- var _loc2_:Array = new Array();
- for each(_loc3_ in _files)
- {
- if(_loc3_.isDirty)
- {
- _loc1_++;
- _loc2_.push({
- "label":_loc3_.name,
- "selected":true,
- "path":_loc3_.path
- });
- }
- }
- if(_loc1_ == 1)
- {
- promptToSaveFile(_loc2_[0].label,_loc2_[0].path);
- }
- else if(_loc1_ > 1)
- {
- _multipleUnsavedDlg = SaveMultipleDialog(PopUpManager.createPopUp(DisplayObject(Application.application),SaveMultipleDialog,true));
- _multipleUnsavedDlg.init(_mockups.inputManager);
- _multipleUnsavedDlg.dataProvider = _loc2_;
- _multipleUnsavedDlg.addEventListener("ok",onMultiplePromptSave);
- PopUpManager.centerPopUp(IFlexDisplayObject(_multipleUnsavedDlg));
- }
- }
-
- protected function restoreSession() : void
- {
- var _loc4_:String = null;
- var _loc5_:Object = null;
- var _loc6_:uint = 0;
- var _loc7_:uint = 0;
- var _loc8_:String = null;
- var _loc1_:ICookieManager = _mockups.model.cookieManager;
- var _loc2_:Object = _loc1_.getProperty("fileName",null);
- if(_loc2_ == null)
- {
- createNewFile();
- }
- else
- {
- _loc5_ = _loc1_.getProperty("lastPathSelected",null);
- if(_loc5_ != null && String(_loc5_).indexOf("?") == -1)
- {
- _loc4_ = String(_loc5_);
- }
- _loc6_ = (_loc2_ as Array).length;
- if(_loc6_ == 0)
- {
- createNewFile();
- }
- else
- {
- _loc7_ = 0;
- while(_loc7_ < _loc6_)
- {
- _loc8_ = _loc2_[_loc7_];
- if(_loc8_.indexOf("?") == -1)
- {
- if(!_loc4_ && _loc7_ == _loc6_ - 1)
- {
- loadFileFromDisk(_loc8_);
- }
- else
- {
- loadDataIntoMemory(_loc8_);
- }
- }
- _loc7_++;
- }
- if(_loc4_)
- {
- if(FileDescriptor(_files[_loc4_]) != null)
- {
- selectFile(_loc4_);
- }
- else
- {
- createNewFile();
- }
- }
- }
- }
- var _loc3_:Object = _loc1_.getProperty("lastOpenPath",null);
- _lastOpenPath = _loc3_ == null ? null : cleanPath(String(_loc3_));
- }
-
- public function snapshotAll() : void
- {
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "snapshotAll";
- return;
- }
- CursorManager.setBusyCursor();
- if(_exportAllFile)
- {
- _exportAllFile.removeEventListener(Event.SELECT,onExportAllSelect);
- _exportAllFile.removeEventListener(Event.CANCEL,onExportAllCancel);
- _exportAllFile = null;
- }
- _exportAllFile = new File();
- _exportAllFile.addEventListener(Event.SELECT,onExportAllSelect);
- _exportAllFile.addEventListener(Event.CANCEL,onExportAllCancel);
- _exportAllFile.browseForDirectory("Where would you like to store the exported PNGs?");
- }
-
- public function savePath(param1:String) : void
- {
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "save";
- return;
- }
- if(param1.indexOf("?") != -1)
- {
- saveAs();
- return;
- }
- updateDataFromMockup();
- saveFileToDisk(param1);
- updateNativeWindowTitle();
- }
-
- override public function log(param1:String) : void
- {
- trace("LOG: " + param1);
- _logger.log(param1);
- }
-
- protected function onExportAllCancel(param1:Event) : void
- {
- _exportAllFile.removeEventListener(Event.SELECT,onExportAllSelect);
- _exportAllFile.removeEventListener(Event.CANCEL,onExportAllCancel);
- _exportAllFile = null;
- }
-
- public function open(param1:Boolean = false) : void
- {
- var p_force:Boolean = param1;
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "open";
- return;
- }
- log("OPEN: _lastOpenPath: null? " + (_lastOpenPath == null) + ", empty? " + (_lastOpenPath == ""));
- try
- {
- if(_openFile != null)
- {
- _openFile.removeEventListener(FileListEvent.SELECT_MULTIPLE,onFileSelectMultiple);
- _openFile.removeEventListener(Event.CANCEL,onFileCancel);
- _openFile = null;
- }
- if(_lastOpenPath == null || _lastOpenPath == "")
- {
- _openFile = File.desktopDirectory;
- }
- else
- {
- _openFile = new File(_lastOpenPath);
- if(Boolean(_openFile) && !_openFile.isDirectory)
- {
- _openFile = _openFile.parent;
- }
- else if(!_openFile)
- {
- _openFile = File.desktopDirectory;
- }
- }
- }
- catch(e:Error)
- {
- Alert.show("problem selecing _openFile:" + e.toString());
- log("problem selecing _openFile:" + e.toString());
- }
- try
- {
- _openFile.addEventListener(FileListEvent.SELECT_MULTIPLE,onFileSelectMultiple);
- _openFile.addEventListener(Event.CANCEL,onFileCancel);
- _openFile.browseForOpenMultiple("",[new FileFilter("Mockups","*.bmml;*.xml"),new FileFilter("XML","*.xml"),new FileFilter("Balsamiq Mockups Markup Language","*.bmml")]);
- }
- catch(e2:Error)
- {
- Alert.show("problem browsing for open:" + e2.toString());
- log("problem browsing for open:" + e2.toString());
- }
- }
-
- protected function onFileCancel(param1:Event) : void
- {
- _openFile.removeEventListener(FileListEvent.SELECT_MULTIPLE,onFileSelectMultiple);
- _openFile.removeEventListener(Event.CANCEL,onFileCancel);
- _openFile = null;
- }
-
- public function quit(param1:Boolean = false) : void
- {
- updateDataFromMockup();
- if(_currentPath != null && getDirtyMockupsCount() > 0 && !param1)
- {
- _ultimateAction = "quit";
- promptToSave();
- }
- else
- {
- saveSession();
- _logger.close();
- Application.application.nativeApplication.exit();
- }
- }
-
- protected function onPromptSave(param1:Event) : void
- {
- if(_unsavedChangesDlg.path.indexOf("?") != -1)
- {
- saveAs();
- return;
- }
- saveFileToDisk(_unsavedChangesDlg.path);
- performUltimateAction();
- }
-
- protected function saveSession() : void
- {
- var _loc2_:FileDescriptor = null;
- var _loc3_:ICookieManager = null;
- var _loc1_:Array = new Array();
- for each(_loc2_ in _files)
- {
- if(_loc2_.path.indexOf("?") == -1)
- {
- _loc1_.push(_loc2_.path);
- }
- }
- _loc3_ = _mockups.model.cookieManager;
- _loc3_.setProperty("fileName",_loc1_);
- if(_currentPath.indexOf("?") == -1)
- {
- _loc3_.setProperty("lastPathSelected",cleanPath(_currentPath));
- }
- _loc3_.setProperty("lastOpenPath",cleanPath(_lastOpenPath));
- }
-
- protected function onReloadNo(param1:Event = null) : void
- {
- _reloadDialog.removeEventListener("yes",onReloadYes);
- _reloadDialog.removeEventListener("no",onReloadNo);
- _reloadDialog.closeYourself();
- _reloadDialog = null;
- }
-
- protected function updateDataFromMockup() : void
- {
- FileDescriptor(_files[_currentPath]).data = _mockups.getXMLData().toXMLString();
- }
-
- protected function onSaveAsCancel(param1:Event) : void
- {
- _saveAsFile.removeEventListener(Event.SELECT,onSaveAsSelect);
- _saveAsFile.removeEventListener(Event.CANCEL,onSaveAsCancel);
- }
-
- public function loadDataIntoMemory(param1:String) : String
- {
- var dataIsValid:Boolean;
- var fileStream:FileStream;
- var f:File = null;
- var data:String = null;
- var xmlData:XML = null;
- var name:String = null;
- var desc:FileDescriptor = null;
- var p_path:String = param1;
- log("loadDataIntoMemory:" + p_path);
- p_path = cleanPath(p_path);
- if(p_path == null || p_path.indexOf("?") != -1)
- {
- return "";
- }
- try
- {
- f = new File(p_path);
- }
- catch(e:Error)
- {
- Alert.show("The file " + p_path + " cannot be loaded (bad path).");
- log("\tERROR: could not load:" + p_path);
- return "";
- }
- if(!f.exists)
- {
- Alert.show("The file " + p_path + " cannot be loaded (file doesn\'t exist).");
- log("\tERROR: file doesn\'t exist");
- return "";
- }
- CursorManager.setBusyCursor();
- fileStream = new FileStream();
- fileStream.open(f,FileMode.READ);
- data = fileStream.readUTFBytes(f.size);
- fileStream.close();
- CursorManager.removeBusyCursor();
- dataIsValid = false;
- try
- {
- xmlData = XML(data);
- dataIsValid = _mockups.model.validateXMLData(xmlData);
- }
- catch(e:Error)
- {
- Alert.show("The file " + f.name + " cannot be loaded (invalid data). Please see the BalsamiqMockups.log files for details");
- log("Data is invalid:");
- log("====\n" + data + "====");
- dataIsValid = false;
- }
- if(dataIsValid)
- {
- name = p_path.replace(/\\/g,"/");
- desc = new FileDescriptor(p_path,unescape(name.substr(name.lastIndexOf("/") + 1)),false,data,f.modificationDate.getTime());
- _files[desc.path] = desc;
- dispatchEvent(new FileManagerEvent(FileManagerEvent.FILE_LIST_CHANGE));
- }
- else
- {
- data = "";
- }
- return data;
- }
-
- protected function takeSnapshot(param1:String = null) : String
- {
- var _loc2_:File = null;
- var _loc5_:String = null;
- var _loc6_:uint = 0;
- if(param1 == null)
- {
- _loc5_ = "mockup";
- if(_currentPath == null || _currentPath.indexOf("?") != -1)
- {
- _loc5_ = "mockup";
- _loc2_ = File.desktopDirectory.resolvePath(_loc5_ + ".png");
- }
- else
- {
- if(_currentPath.lastIndexOf(".") == -1)
- {
- _loc5_ = _currentPath;
- }
- else
- {
- _loc5_ = _currentPath.substr(0,_currentPath.lastIndexOf("."));
- }
- if(_isExportingAll)
- {
- _loc5_ = _exportAllTargetDirPath + _loc5_.substr(_loc5_.lastIndexOf(File.separator));
- }
- _loc2_ = new File(_loc5_ + ".png");
- }
- if(_loc2_.exists)
- {
- if(!(_isExportingAll && _exportingAllAlwaysOverwrite))
- {
- _loc6_ = 1;
- while(_loc2_.exists)
- {
- _loc6_++;
- if(_currentPath == null || _currentPath.indexOf("?") != -1)
- {
- _loc2_ = File.desktopDirectory.resolvePath(_loc5_ + "_" + _loc6_ + ".png");
- }
- else
- {
- _loc2_ = new File(_loc5_ + "_" + _loc6_ + ".png");
- }
- }
- _exportPNGDialog = ExportPNGConfirmationDialog(PopUpManager.createPopUp(DisplayObject(Application.application),ExportPNGConfirmationDialog,true));
- _exportPNGDialog.kind = _isExportingAll ? ExportPNGConfirmationDialog.KIND_MULTIPLE : ExportPNGConfirmationDialog.KIND_SINGLE;
- _exportPNGDialog.initExportPNGConfirmationDialog(_mockups.inputManager,_loc5_,_loc2_);
- _exportPNGDialog.addEventListener("exportClick",onExportPNGDialogClick);
- PopUpManager.centerPopUp(IFlexDisplayObject(_exportPNGDialog));
- return null;
- }
- }
- }
- else
- {
- _loc2_ = new File(param1);
- }
- var _loc3_:ByteArray = _mockups.getPNGsnapshot();
- var _loc4_:FileStream = new FileStream();
- _loc4_.open(_loc2_,FileMode.WRITE);
- _loc4_.writeBytes(_loc3_);
- _loc4_.close();
- return _loc2_.nativePath;
- }
-
- public function newMockup() : void
- {
- createNewFile();
- }
-
- public function closeAllFiles() : void
- {
- var _loc1_:FileDescriptor = null;
- var _loc2_:Boolean = false;
- if(_currentPath == null)
- {
- return;
- }
- for each(_loc1_ in _files)
- {
- _loc2_ = _loc1_.isDirty;
- closeFileWithPrompt(_loc1_.path);
- if(_loc2_)
- {
- break;
- }
- }
- }
-
- protected function onReloadYes(param1:Event) : void
- {
- var _loc2_:String = _currentPath;
- closeCurrentFile(true);
- loadFileFromDisk(_loc2_);
- onReloadNo();
- }
-
- protected function onMultiplePromptSave(param1:Event) : void
- {
- var _loc2_:Object = null;
- for each(_loc2_ in _multipleUnsavedDlg.dataProvider)
- {
- if(_loc2_.selected)
- {
- if(_loc2_.path.indexOf("?") != -1)
- {
- saveAs();
- }
- else
- {
- saveFileToDisk(_loc2_.path);
- }
- }
- }
- performUltimateAction();
- }
-
- public function deactivate() : void
- {
- var sqlStatement:SQLStatement = null;
- var debugSqlConnection:SQLConnection = new SQLConnection();
- try
- {
- debugSqlConnection.open(_dbFile,SQLMode.UPDATE);
- sqlStatement = new SQLStatement();
- sqlStatement.sqlConnection = debugSqlConnection;
- sqlStatement.text = "DROP TABLE activation;";
- sqlStatement.execute();
- debugSqlConnection.close();
- }
- catch(e:Error)
- {
- trace("wha?" + e.errorID + ", " + e.toString());
- }
- _activated = false;
- }
-
- public function save() : void
- {
- if(_currentPath == null)
- {
- return;
- }
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "save";
- return;
- }
- if(_currentPath.indexOf("?") != -1)
- {
- saveAs();
- return;
- }
- log("save, saving currentPath in model:" + _currentPath);
- _mockups.model.currentPath = _currentPath;
- updateDataFromMockup();
- saveFileToDisk(_currentPath);
- saveSession();
- setDirty(false);
- performUltimateAction();
- updateNativeWindowTitle();
- }
-
- public function closeFileWithPrompt(param1:String, param2:Boolean = false) : void
- {
- if(FileDescriptor(_files[param1]).isDirty && !param2)
- {
- _ultimateAction = "close";
- updateDataFromMockup();
- promptToSaveFile(FileDescriptor(_files[param1]).name,param1);
- }
- else
- {
- trace("closeFileWithPrompt " + param1);
- closeFile(param1);
- saveSession();
- if(_currentPath == null)
- {
- _mockups.model.clearCurrentMockup();
- }
- }
- }
-
- override protected function setCurrentPath(param1:String) : void
- {
- log("setCurrentPath:" + param1);
- super.setCurrentPath(param1);
- _mockups.model.currentPath = _currentPath;
- _checkForUpdatesTimer.stop();
- if(_currentPath.indexOf("?") == -1)
- {
- onCheckForUpdates();
- trace("STARTING TIMER!");
- _checkForUpdatesTimer.start();
- }
- }
-
- protected function exportNextPath() : void
- {
- var _loc1_:FileDescriptor = null;
- if(_pathsToExportIndex > 0)
- {
- --_pathsToExportIndex;
- _loc1_ = _pathsToExport[_pathsToExportIndex];
- selectFile(_loc1_.path);
- }
- else
- {
- PopUpManager.removePopUp(_exportingDlg);
- _exportingDlg = null;
- _pathsToExportIndex = 0;
- _pathsToExport = null;
- _mockups.model.removeEventListener(MockupModelEvent.VIEW_IS_READY,onViewIsReady);
- _isExportingAll = false;
- _exportingAllAlwaysOverwrite = false;
- _exportAllTargetDirPath = null;
- CursorManager.removeBusyCursor();
- _confirmDlg = ConfirmationDialog(PopUpManager.createPopUp(DisplayObject(Application.application),ConfirmationDialog,true));
- _confirmDlg.init(_mockups.inputManager);
- _confirmDlg.dialogTitle = "Images Saved";
- _confirmDlg.message = "Your mockups were exported to \n" + _exportedPaths;
- PopUpManager.centerPopUp(IFlexDisplayObject(_confirmDlg));
- }
- }
-
- public function saveAs() : void
- {
- if(_currentPath == null)
- {
- return;
- }
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "saveas";
- return;
- }
- log("saveAs: _lastOpenPath:" + _lastOpenPath);
- try
- {
- if(_saveAsFile)
- {
- _saveAsFile.removeEventListener(Event.SELECT,onSaveAsSelect);
- _saveAsFile.removeEventListener(Event.CANCEL,onSaveAsCancel);
- }
- if(_lastOpenPath == null || _lastOpenPath == "")
- {
- _saveAsFile = File.desktopDirectory;
- }
- else
- {
- _saveAsFile = new File(_lastOpenPath);
- if(Boolean(_saveAsFile) && !_saveAsFile.isDirectory)
- {
- _saveAsFile = _saveAsFile.parent;
- }
- else if(!_saveAsFile)
- {
- _saveAsFile = File.desktopDirectory;
- }
- }
- }
- catch(e:Error)
- {
- Alert.show("unable to select _saveAsFile: " + e.toString());
- log("unable to select _saveAsFile: " + e.toString());
- }
- try
- {
- log("_saveAsFile.nativePath:" + _saveAsFile.nativePath);
- _saveAsFile.addEventListener(Event.SELECT,onSaveAsSelect);
- _saveAsFile.addEventListener(Event.CANCEL,onSaveAsCancel);
- _saveAsFile.browseForSave("");
- }
- catch(e2:Error)
- {
- Alert.show("unable to start save-as operation: " + e2.toString());
- log("unable to start save-as operation: " + e2.toString());
- }
- }
-
- public function setDirty(param1:Boolean = true, param2:Boolean = false) : void
- {
- if(param2)
- {
- return;
- }
- if(_currentPath != null && FileDescriptor(_files[_currentPath]).isDirty != param1)
- {
- FileDescriptor(_files[_currentPath]).isDirty = param1;
- updateNativeWindowTitle();
- dispatchEvent(new FileManagerEvent(FileManagerEvent.FILE_LIST_CHANGE));
- }
- }
-
- public function getImageURL(param1:String) : String
- {
- return param1;
- }
-
- override public function saveAllFilesToDisk() : void
- {
- updateDataFromMockup();
- super.saveAllFilesToDisk();
- }
-
- protected function getDirtyMockupsCount() : uint
- {
- var _loc2_:FileDescriptor = null;
- var _loc1_:uint = 0;
- for each(_loc2_ in _files)
- {
- if(_loc2_.isDirty)
- {
- _loc1_++;
- }
- }
- return _loc1_;
- }
-
- override public function selectFile(param1:String) : void
- {
- var _loc2_:Array = null;
- var _loc5_:Boolean = false;
- if(_files[param1] == null)
- {
- return;
- }
- if(_currentPath)
- {
- updateDataFromMockup();
- _loc5_ = FileDescriptor(_files[_currentPath]).isDirty;
- _mockups.model.allowNonDraggingKeyCommands = true;
- _mockups.model.clearCurrentMockup();
- _loc2_ = _mockups.model.getClipboard();
- setDirty(_loc5_);
- }
- super.selectFile(param1);
- var _loc3_:XML = new XML(FileDescriptor(_files[_currentPath]).data);
- var _loc4_:Boolean = _mockups.model.validateXMLData(_loc3_);
- if(_loc4_)
- {
- _mockups.model.loadXMLData(_loc3_,_currentPath);
- }
- else
- {
- createNewFile();
- }
- if(_loc2_)
- {
- _mockups.model.setClipboard(_loc2_);
- }
- updateNativeWindowTitle();
- }
-
- public function registerWithKey(param1:String, param2:String) : Boolean
- {
- var _loc3_:Boolean = isValidKey(param1,param2);
- if(_loc3_)
- {
- activate();
- }
- return _loc3_;
- }
-
- public function closeCurrentFile(param1:Boolean = false) : void
- {
- if(_currentPath == null)
- {
- return;
- }
- closeFileWithPrompt(_currentPath,param1);
- }
-
- protected function onExportPNGDialogClick(param1:Event) : void
- {
- var _loc3_:String = null;
- _exportPNGDialog.removeEventListener("exportClick",onExportPNGDialogClick);
- trace(_exportPNGDialog.selection,_exportPNGDialog.fullPathToUse);
- var _loc2_:Boolean = false;
- switch(_exportPNGDialog.selection)
- {
- case ExportPNGConfirmationDialog.SELECTION_APPEND:
- case ExportPNGConfirmationDialog.SELECTION_REPLACE:
- if(_isExportingAll)
- {
- _loc2_ = true;
- }
- else
- {
- snapshot(_exportPNGDialog.fullPathToUse);
- }
- break;
- case ExportPNGConfirmationDialog.SELECTION_REPLACE_ALL:
- if(_isExportingAll)
- {
- _exportingAllAlwaysOverwrite = true;
- _loc2_ = true;
- }
- }
- _exportPNGDialog.closeYourself();
- if(_loc2_)
- {
- _loc3_ = takeSnapshot(_exportPNGDialog.fullPathToUse);
- _exportedPaths += _loc3_ + "\n";
- exportNextPath();
- }
- }
-
- public function register() : void
- {
- if(!_activated)
- {
- openActivateDialog();
- }
- else
- {
- if(Boolean(_confirmDlg) && Boolean(_confirmDlg.parent))
- {
- return;
- }
- _confirmDlg = ConfirmationDialog(PopUpManager.createPopUp(DisplayObject(Application.application),ConfirmationDialog,true));
- _confirmDlg.dialogTitle = "Software Already Registered";
- _confirmDlg.message = "Your copy of Balsamiq Mockups for Desktop has already been registered.";
- _confirmDlg.init(_mockups.inputManager);
- PopUpManager.centerPopUp(IFlexDisplayObject(_confirmDlg));
- }
- }
-
- public function print() : void
- {
- _mockups.print();
- }
-
- protected function getPrettyPath() : String
- {
- var _loc1_:FileDescriptor = null;
- var _loc2_:String = null;
- if(_currentPath)
- {
- _loc1_ = getFileDescriptor(_currentPath);
- _loc2_ = getFileDescriptor(_currentPath).path;
- if(_loc1_.name == "")
- {
- _loc2_ = "New Mockup";
- }
- return _loc2_;
- }
- return "";
- }
-
- protected function performUltimateAction() : void
- {
- if(_ultimateAction == null)
- {
- return;
- }
- switch(_ultimateAction)
- {
- case "open":
- open(true);
- break;
- case "close":
- closeCurrentFile(true);
- break;
- case "quit":
- quit(true);
- }
- _ultimateAction = null;
- }
-
- protected function promptToSaveFile(param1:String, param2:String) : void
- {
- if(Boolean(_unsavedChangesDlg) && Boolean(_unsavedChangesDlg.parent))
- {
- return;
- }
- _unsavedChangesDlg = UnsavedChangesDialog(PopUpManager.createPopUp(DisplayObject(Application.application),UnsavedChangesDialog,true));
- _unsavedChangesDlg.init(_mockups.inputManager);
- _unsavedChangesDlg.setFileNamePath(param1,param2);
- _unsavedChangesDlg.addEventListener("save",onPromptSave);
- _unsavedChangesDlg.addEventListener("dontsave",onPromptDontSave);
- PopUpManager.centerPopUp(IFlexDisplayObject(_unsavedChangesDlg));
- }
-
- override public function saveFileToDisk(param1:String) : void
- {
- if(param1.indexOf("?") != -1)
- {
- return;
- }
- log("saveFileToDisk:" + param1);
- super.saveFileToDisk(param1);
- updateNativeWindowTitle();
- var _loc2_:FileDescriptor = FileDescriptor(_files[param1]);
- _mockups.model.localMockupsCache.cacheMockup(_loc2_.name,_loc2_.data);
- }
-
- public function snapshot(param1:String = null) : void
- {
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "snapshot";
- return;
- }
- CursorManager.setBusyCursor();
- var _loc2_:String = takeSnapshot(param1);
- if(_loc2_ == null)
- {
- return;
- }
- CursorManager.removeBusyCursor();
- if(Boolean(_confirmDlg) && Boolean(_confirmDlg.parent))
- {
- PopUpManager.removePopUp(_confirmDlg);
- _confirmDlg = null;
- }
- _confirmDlg = ConfirmationDialog(PopUpManager.createPopUp(DisplayObject(Application.application),ConfirmationDialog,true));
- _confirmDlg.init(_mockups.inputManager);
- _confirmDlg.dialogTitle = "Image Saved";
- _confirmDlg.message = "Your mockup was exported to " + _loc2_;
- PopUpManager.centerPopUp(IFlexDisplayObject(_confirmDlg));
- }
-
- protected function onExportAllSelect(param1:Event) : void
- {
- var _loc2_:FileDescriptor = null;
- _exportAllFile.removeEventListener(Event.SELECT,onExportAllSelect);
- _exportAllFile.removeEventListener(Event.CANCEL,onExportAllCancel);
- _exportAllTargetDirPath = File(param1.target).nativePath;
- trace(_exportAllTargetDirPath);
- _mockups.model.addEventListener(MockupModelEvent.VIEW_IS_READY,onViewIsReady);
- _isExportingAll = true;
- _pathsToExport = [getFileDescriptor(_currentPath)];
- for each(_loc2_ in _files)
- {
- if(_loc2_.path != _currentPath)
- {
- _pathsToExport.push(_loc2_);
- }
- }
- _exportedPaths = "";
- _pathsToExportIndex = _pathsToExport.length;
- _exportingDlg = LoadingPopUp(PopUpManager.createPopUp(DisplayObject(Application.application),LoadingPopUp,true));
- _exportingDlg.title = "Exporting " + _pathsToExport.length + " Mockups...";
- _exportingDlg.progressBar.indeterminate = true;
- PopUpManager.centerPopUp(_exportingDlg);
- PopUpManager.bringToFront(_exportingDlg);
- exportNextPath();
- _exportAllFile = null;
- }
-
- public function get activated() : Boolean
- {
- return _activated;
- }
-
- public function onViewIsReady(param1:MockupModelEvent) : void
- {
- if(!_isExportingAll)
- {
- return;
- }
- var _loc2_:String = takeSnapshot();
- if(_loc2_ == null)
- {
- return;
- }
- _exportedPaths += _loc2_ + "\n";
- exportNextPath();
- }
-
- public function onClosing(param1:Event) : void
- {
- quit();
- param1.preventDefault();
- }
-
- override public function createCloneOfCurrentMockup() : void
- {
- var _loc1_:String = null;
- if(_currentPath != null)
- {
- updateDataFromMockup();
- _loc1_ = _mockups.getXMLData(true).toXMLString();
- createNewFile(_loc1_);
- }
- }
-
- protected function updateNativeWindowTitle() : void
- {
- var _loc1_:String = "Balsamiq Mockups For Desktop";
- if(_currentPath != null)
- {
- _loc1_ += " - " + (FileDescriptor(_files[_currentPath]).isDirty ? "* " : "") + getPrettyPath();
- }
- Application.application.stage.nativeWindow.title = _loc1_;
- }
-
- protected function onActivateDialogActivate(param1:Event) : void
- {
- activate();
- }
-
- protected function onPromptDontSave(param1:Event) : void
- {
- performUltimateAction();
- }
-
- protected function activate() : void
- {
- _activated = true;
- dispatchEvent(new Event("activateChange"));
- _sqlConnection.open(_dbFile,SQLMode.CREATE);
- var _loc1_:SQLStatement = new SQLStatement();
- _loc1_.sqlConnection = _sqlConnection;
- _loc1_.text = "CREATE TABLE activation (id INTEGER PRIMARY KEY, status BOOLEAN);";
- _loc1_.execute();
- _loc1_ = new SQLStatement();
- _loc1_.sqlConnection = _sqlConnection;
- _loc1_.text = "INSERT INTO activation (id, status) VALUES (0, true);";
- _loc1_.execute();
- _sqlConnection.close();
- var _loc2_:String = _activateDialog.toDoNext;
- PopUpManager.removePopUp(_activateDialog);
- switch(_loc2_)
- {
- case "save":
- save();
- break;
- case "open":
- open();
- break;
- case "saveas":
- saveAs();
- break;
- case "snapshot":
- snapshot();
- break;
- case "snapshotAll":
- snapshotAll();
- }
- }
-
- public function snapshotToClipboard() : void
- {
- if(!_activated)
- {
- openActivateDialog();
- _activateDialog.toDoNext = "snapshot";
- return;
- }
- var _loc1_:BitmapData = _mockups.getPNGBitmapData();
- Clipboard.generalClipboard.setData(ClipboardFormats.BITMAP_FORMAT,_loc1_);
- }
-
- protected function onSaveAsSelect(param1:Event) : void
- {
- var _loc2_:String = _saveAsFile.nativePath;
- log("onSaveAsSelect:" + _loc2_ + " null? " + (_loc2_ == null) + ", empty? " + (_loc2_ == ""));
- if(File(param1.target) != null)
- {
- log("\tp_evt.target: #" + File(param1.target).nativePath + "#");
- }
- if(_loc2_ == null || _loc2_ == "")
- {
- Alert.show("Error saving file:" + _saveAsFile.url);
- return;
- }
- _saveAsFile.removeEventListener(Event.SELECT,onSaveAsSelect);
- _saveAsFile.removeEventListener(Event.CANCEL,onSaveAsCancel);
- var _loc3_:String = _currentPath;
- setCurrentPath(cleanPath(_loc2_));
- _lastOpenPath = cleanPath(_loc2_);
- if(_currentPath.substr(_currentPath.length - 4).toLowerCase() != ".xml" && _currentPath.substr(_currentPath.length - 5).toLowerCase() != ".bmml")
- {
- setCurrentPath(_currentPath + ".bmml");
- }
- var _loc4_:FileDescriptor = FileDescriptor(_files[_loc3_]).clone();
- _loc4_.path = _currentPath;
- var _loc5_:String = _currentPath.replace(/\\/g,"/");
- _loc4_.name = unescape(_loc5_.substr(_loc5_.lastIndexOf("/") + 1));
- _files[_currentPath] = _loc4_;
- if(_loc3_ != _currentPath)
- {
- _files[_loc3_] = null;
- delete _files[_loc3_];
- }
- save();
- }
-
- public function close() : void
- {
- if(_logger)
- {
- _logger.close();
- }
- }
- }
- }
-
-